﻿#ifndef SENDDATABUFFER_H
#define SENDDATABUFFER_H
//

#include <mutex>

#define CHANNAL_COUNT 10     // 通道数
#define DATA_COUNT  40       // 缓存数
#define BUFFER_SIZE  1024    // 缓存大小

typedef struct
{
    int channelId ;
	int dataLen ;
    unsigned char dataBuf[BUFFER_SIZE] ;
} DATABUFFER;


class SendDataBuffer
{
private:
    std::mutex m_mutex;
public:
	
    bool writeDataToBuffer(int channelIndex, unsigned char *buf, int len);
    bool readDataFromBuffer(int channelIndex, char *buf, int bufLength ,int &getLength);

public:
    SendDataBuffer();
    SendDataBuffer(SendDataBuffer&)=delete;
    SendDataBuffer& operator=(const SendDataBuffer&)=delete;
    ~SendDataBuffer() = default;

    static SendDataBuffer& getInstance();
private:
    // 多通道缓存
    DATABUFFER m_sendBuffer[CHANNAL_COUNT][DATA_COUNT] ;
    // 读索引
    int m_readIndex[CHANNAL_COUNT] ;
    // 写索引
    int m_writeIndex[CHANNAL_COUNT] ;
	
};
#endif
